﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;


public class tbPositionsDB
{
    #region[tbPositions_Add]
    public static bool tbPositions_Add(tbPositionsDATA _tbPositionsDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbPositions_Add", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@psCode", _tbPositionsDATA.psCode));
                dbCmd.Parameters.Add(new SqlParameter("@psName", _tbPositionsDATA.psName));
                dbCmd.Parameters.Add(new SqlParameter("@psLevel", _tbPositionsDATA.psLevel));
                dbCmd.Parameters.Add(new SqlParameter("@psOrd", _tbPositionsDATA.psOrd));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbPositions_Update]
    public static bool tbPositions_Update(tbPositionsDATA _tbPositionsDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbPositions_Update", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@psID", _tbPositionsDATA.psID));
                dbCmd.Parameters.Add(new SqlParameter("@psCode", _tbPositionsDATA.psCode));
                dbCmd.Parameters.Add(new SqlParameter("@psName", _tbPositionsDATA.psName));
                dbCmd.Parameters.Add(new SqlParameter("@psLevel", _tbPositionsDATA.psLevel));
                dbCmd.Parameters.Add(new SqlParameter("@psOrd", _tbPositionsDATA.psOrd));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbPositions_Delete]
    public static bool tbPositions_Delete(string psID)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbPositions_Delete", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@psID", psID));
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbPositions_GetByAll]
    public static List<tbPositionsDATA> tbPositions_GetByAll()
    {
        List<tbPositionsDATA> list = new List<tbPositionsDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbPositions_GetByAll", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbPositionsDATA objtbPositionsDATA = new tbPositionsDATA(
                        reader["psID"].ToString(),
                        reader["psCode"].ToString(),
                        reader["psName"].ToString(),
                        reader["psLevel"].ToString(),
                        reader["psOrd"].ToString());
                        list.Add(objtbPositionsDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
    #region[tbPositions_GetByID]
    public static List<tbPositionsDATA> tbPositions_GetByID(string psID)
    {
        List<tbPositionsDATA> list = new List<tbPositionsDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbPositions_GetByID", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@psID", psID));
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbPositionsDATA objtbPositionsDATA = new tbPositionsDATA(
                        reader["psID"].ToString(),
                        reader["psCode"].ToString(),
                        reader["psName"].ToString(),
                        reader["psLevel"].ToString(),
                        reader["psOrd"].ToString());
                        list.Add(objtbPositionsDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
}
